package com.qianfeng.zhangwei.xutils.recycler.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lidroid.xutils.BitmapUtils;
import com.qianfeng.zhangwei.xutils.R;
import com.qianfeng.zhangwei.xutils.recycler.bean.Good;

import java.util.List;

/**
 * @说 明：
 * @项目名称：Sz1504Adv
 * @包 名： com.qianfeng.zhangwei.xutils.adapter
 * @类 名： RecyclerBaseAdapter
 * @创 建人： zhangwei
 * @创建时间：2015-08-05 14:36
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class StaggerBaseAdapter extends RecyclerView.Adapter<StaggerBaseAdapter.RcViewHolder> {
    private List<Good> list;
    private OnItemClickLinstener onItemClickLinstener;
    BitmapUtils bitmapUtils;


    public StaggerBaseAdapter(Context context, List<Good> list) {
        this.list = list;
        bitmapUtils = new BitmapUtils(context);
        bitmapUtils.configDefaultLoadFailedImage(R.mipmap.ic_launcher);
        bitmapUtils.configDefaultLoadingImage(R.mipmap.ic_launcher);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public RcViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.widget_item_stagger_layout, parent, false);
        RcViewHolder vh = new RcViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(RcViewHolder holder, int position) {
//        ViewGroup.LayoutParams params = holder.img.getLayoutParams();
//        params.height = Integer.valueOf(list.get(position).getPic_height());
//        params.width = Integer.valueOf(list.get(position).getPic_width());
        bitmapUtils.display(holder.img, list.get(position).getPic_url());
    }


    public class RcViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private ImageView img;

        public RcViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);
            this.img = (ImageView) itemView.findViewById(R.id.item_stagger_img);
        }

        @Override
        public void onClick(View v) {
            if (onItemClickLinstener != null) {
                onItemClickLinstener.onItemClickLinstener(getLayoutPosition());
            }
        }
    }


    public interface OnItemClickLinstener {
        public void onItemClickLinstener(int position);

    }

    public void setOnItemClickLinstener(OnItemClickLinstener onItemClickLinstener) {
        this.onItemClickLinstener = onItemClickLinstener;
    }
}
